package com.winchain.chainbill.basic.invoice.rx;

import com.shell.bee.invoince.po.InvDfr;
import com.shell.bee.invoince.service.InvDfrService;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.tbill.base.po.TbDct;
import com.winchain.chainbill.tbill.biz.TBill;
import com.winchain.chainbill.tbill.biz.TBillEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TBillInvoiceDfrUploadUpdateSubscriber extends OnErrorNotImplementedSubscriber<TBillEvent<TbDct>> {
	@Autowired
	private InvDfrService invDfrService;

	public void onApplicationEvent(TBillEvent<TbDct> t) {
		TbDct dct = (TbDct) t.getBill().getSource();
		if (dct == null) {
			return;
		}
		String dfrState = t.getStringValue("dfrState");
		if (dfrState != null) {
			InvDfr invDfr = this.invDfrService.selectByBiz(dct.getDctId(), "2");
			if (invDfr != null) {
				String uploadDate = t.getStringValue("uploadDate");
				String remark = t.getStringValue("remark");
				invDfr.setState(dfrState);
				invDfr.setUploadDate(uploadDate);
				invDfr.setRemark(remark);
				this.invDfrService.updateNotNull(invDfr);
			}
		}
	}
}
